package com.qing.springcloud.config;

import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author caozhipeng
 * @date 2025/7/9
 */
@Configuration
public class RabbitMQConfig {

    @Bean
    public RabbitTemplate rabbitTemplate(ConnectionFactory connectionFactory) {
        RabbitTemplate template = new RabbitTemplate(connectionFactory);
        template.setMessageConverter(new Jackson2JsonMessageConverter());
        return template;
    }

    @Bean
    public DirectExchange friendExchange() {
        return new DirectExchange("friend-exchange");
    }

    @Bean
    public TopicExchange groupExchange() {
        return new TopicExchange("group-exchange");
    }

    @Bean
    public DirectExchange directExchange() {
        return new DirectExchange("direct_exchange");
    }

//    // 声明 Direct 类型的交换机
//    @Bean
//    public DirectExchange directExchange() {
//        return new DirectExchange("direct-exchange");
//    }
//
//    // 声明 Topic 类型的交换机
//    @Bean
//    public TopicExchange topicExchange() {
//        return new TopicExchange("topic-exchange");
//    }
//
//    // 声明 Fanout 类型的交换机
//    @Bean
//    public FanoutExchange fanoutExchange() {
//        return new FanoutExchange("fanout-exchange");
//    }

}